﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core
{
	/// <summary>
	/// The Size of a map.
	/// </summary>
	[System.Diagnostics.DebuggerDisplay("MapSize Columns: {Columns} Rows: {Rows}")]
	public class MapSize
	{

		#region Variablen
	
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the number of rows.
		/// </summary>
		/// <value>
		/// The rows.
		/// </value>
		public int Rows { get; set; }
		/// <summary>
		/// Gets or sets the number of columns.
		/// </summary>
		/// <value>
		/// The columns.
		/// </value>
		public int Columns { get; set; }
		/// <summary>
		/// Gets the field count.
		/// </summary>
		public int FieldCount { get { return this.Rows * this.Columns; } }
		#endregion

		#region Methoden

		/// <summary>
		/// Initializes a new instance of the <see cref="MapSize"/> struct.
		/// </summary>
		public MapSize()
		{

		}

		/// <summary>
		/// Initializes a new instance of the <see cref="MapSize"/> struct.
		/// </summary>
		/// <param name="columns">The columns.</param>
		/// <param name="rows">The rows.</param>
		public MapSize( int columns, int rows )
		{
			if( columns <= 0 ) throw new ArgumentOutOfRangeException( "columns <= 0" );
			if( rows <= 0 ) throw new ArgumentOutOfRangeException( "rows <= 0" );

			this.Columns = columns;
			this.Rows = rows;
		}

		/// <summary>
		/// Determines whether [is valid column] [the specified column index].
		/// </summary>
		/// <param name="columnIndex">Index of the column.</param>
		/// <returns>
		///   <c>true</c> if [is valid column] [the specified column index]; otherwise, <c>false</c>.
		/// </returns>
		public bool IsValidColumn( int columnIndex )
		{
			return columnIndex >= 0 && columnIndex < this.Columns;
		}

		/// <summary>
		/// Determines whether [is valid row] [the specified row index].
		/// </summary>
		/// <param name="rowIndex">Index of the row.</param>
		/// <returns>
		///   <c>true</c> if [is valid row] [the specified row index]; otherwise, <c>false</c>.
		/// </returns>
		public bool IsValidRow( int rowIndex )
		{
			return rowIndex >= 0 && rowIndex < this.Rows;
		}

		/// <summary>
		/// Determines whether the specified position is valid.
		/// </summary>
		/// <param name="position">The position.</param>
		/// <returns>
		///   <c>true</c> if the specified position is valid; otherwise, <c>false</c>.
		/// </returns>
		public bool IsValid( Position position )
		{
			if( position == null )throw new ArgumentNullException( "position" );

			return this.IsValidRow( position.Row ) && 
					this.IsValidColumn( position.Column );
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return string.Format( "{0}/{1}", this.Rows, this.Columns );
		}

		#endregion

	}
}